package com.citywithincity.db.drivers.mysql;

import com.citywithincity.db.ArFactory;
import com.citywithincity.db.ArFactoryImpl;
import com.citywithincity.db.ConnectionDescription;
import com.citywithincity.db.interfaces.IDataSourceProvider;
import com.citywithincity.db.interfaces.SqlDriver;
import com.citywithincity.db.meta.DbStructFactory;
import com.citywithincity.db.meta.impl.mysql.MysqlDbStruct;

public class MysqlConnDescription extends ConnectionDescription {
	
	public static final int DEFAULT_PORT = 3306;
	
	private String dbName;
	private int port = DEFAULT_PORT;
	
	
	public MysqlConnDescription() {
		
	}
	
	@Override
	public String getJdbcUrl() {
		return "jdbc:mysql://"+getServer()+":"+ port + "/"+getDbName()+"?useUnicode=true&characterEncoding=UTF-8";
	}
	
	public MysqlConnDescription(String server,int port,String db,String user,String password){
		setPassword(password);
		setUser(user);
		setDriverClass("com.mysql.jdbc.Driver");
		setServer(server);
		this.setDbName(db);
		this.port = port;
	}
	
	public MysqlConnDescription(String server,String db,String user,String password){
		this(server, DEFAULT_PORT, db, user, password);
	}

	@Override
	public ArFactory create(IDataSourceProvider ds) {
		return new ArFactoryImpl(this,ds);
	}


	public String getDbName() {
		return dbName;
	}


	public int getPort() {
		return port;
	}


	@Override
	protected SqlDriver createDriver() {
		return new MysqlDriver();
	}

	@Override
	protected DbStructFactory createStruct(SqlDriver sqlDriver) {
		return new MysqlDbStruct(sqlDriver, getDbName());
	}

	public void setDbName(String dbName) {
		this.dbName = dbName;
	}



	
	
}
